try:
    f = open("g:/1.txt","r",encoding="UTF-8")
    res = f.read()
    print(res)
except:
    print("载入错误")
finally:
    f.close()

#---------------------------

#name = "我定义了这个变量"
try:
    print(name)
    print(1/0)
except (NameError,ZeroDivisionError) as e:
    print(f"程序运行时出现错误,详情: {e}")


# 捕获所有异常
try:
    #print(name)
    print(1/0)
except Exception as e:
    print(f"有错误: {e}")
else:
    print("很好，没有出现异常！")